package com.cqtczh.qhd.driver.acticity.carteam;

import httptools.HttpJsonTool;

import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javabeen.CarTeamIdBeen;
import javabeen.CompleteCarTeamInfoBeen;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.reflect.TypeToken;
import com.cqtczh.qhd.driver.AppContent;
import com.cqtczh.qhd.driver.R;
import com.cqtczh.qhd.driver.acticity.base.BaseActivity;
import com.cqtczh.qhd.driver.api.GagApi;

public class CompleteCarTeamInfo extends BaseActivity {
	private List<CarTeamIdBeen> member = new ArrayList<CarTeamIdBeen>();
	private String completeCarTeamID;
	private AppContent app;
	private CompleteCarTeamInfoBeen completeinfobeen;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_car_team_info);
		app = (AppContent) getApplication();
		Intent intent = getIntent();
		completeCarTeamID = intent.getStringExtra("CompleteCarTeamInfo");
		completeinfobeen = (CompleteCarTeamInfoBeen) intent
				.getSerializableExtra("completeinfobeen");
		if (completeCarTeamID != null) {
			IniUI();
		} else {
			Toast.makeText(this, "公司车队ID为空", Toast.LENGTH_LONG).show();
		}
	}

	private void IniUI() {
		TextView headtitle = (TextView) findViewById(R.id.head_title);
		headtitle.setVisibility(View.VISIBLE);
		headtitle.setText("公司车队信息");
		ImageView headleft = (ImageView) findViewById(R.id.head_left);
		headleft.setVisibility(View.VISIBLE);
		headleft.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				CompleteCarTeamInfo.this.finish();
			}
		});
		TextView textView1 = (TextView) findViewById(R.id.ctextVew1);
		// textView1.setVisibility(View.GONE);
		TextView textView2 = (TextView) findViewById(R.id.ctextVew3);
		TextView textView3 = (TextView) findViewById(R.id.ctextVew4);
		TextView textView4 = (TextView) findViewById(R.id.ctextVew2);
		textView1.setText("公司名字：" + completeinfobeen.getCompanyname());
		textView2.setText("公司车队队长：" + completeinfobeen.getCarownername());
		textView3.setText("公司车队队长电话：" + completeinfobeen.getPhone());
		textView4.setText("车队名字：" + completeinfobeen.getOrgname());
		Button agree = (Button) findViewById(R.id.arrge);
		agree.setVisibility(View.GONE);
		Button reg = (Button) findViewById(R.id.reg);
		reg.setVisibility(View.GONE);
		Button chek = (Button) findViewById(R.id.chek);
		if (app.userId.equals(completeinfobeen.getLeaderid()+"")) {

			chek.setVisibility(View.VISIBLE);
			chek.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					GetCarteamMember();
				}
			});
		}
	}

	private void GetCarteamMember() {
		HttpJsonTool httpJsonTool = new HttpJsonTool(this);

		HashMap<String, String> data = new HashMap<String, String>();
		data.put("orgid", completeCarTeamID);
		httpJsonTool.SetOnLister(new Handler() {
			@Override
			public void handleMessage(Message msg) {
				// TODO Auto-generated method stub
				super.handleMessage(msg);
				if (msg.what == 1) {
					Intent intent = new Intent(CompleteCarTeamInfo.this,
							CompleteCarTeamMember.class);
					member = (List<CarTeamIdBeen>) msg.obj;
					intent.putExtra("carmembers", (Serializable) member);

					startActivity(intent);
				}
			}
		});
		Type type = new TypeToken<List<CarTeamIdBeen>>() {
		}.getType();
		httpJsonTool.StartWork(data, GagApi.GET_COMPLETE_CARTEAMMEMBER, type,
				null);
	}
}
